﻿using BarManager.Core.Entity;
using System.Data.Entity.ModelConfiguration;

namespace BarManager.Infrastructure.Data.Mapping
{
    public class DomicilioMap : EntityTypeConfiguration<Domicilio>
    {
        public DomicilioMap()
        {
            // Primary Key
            this.HasKey(t => t.Id);

            // Properties
            this.Property(t => t.Calle)
                .IsRequired()
                .HasMaxLength(150);

            this.Property(t => t.EntreCalles)
                .HasMaxLength(150);

            this.Property(t => t.Departamento)
                .HasMaxLength(10);

            this.Property(t => t.Barrio)
                .HasMaxLength(150);

            // Table & Column Mappings
            this.ToTable("Domicilio");
            this.Property(t => t.Id).HasColumnName("Id");
            this.Property(t => t.ClienteId).HasColumnName("ClienteId");
            this.Property(t => t.Calle).HasColumnName("Calle");
            this.Property(t => t.Numero).HasColumnName("Numero");
            this.Property(t => t.EntreCalles).HasColumnName("EntreCalles");
            this.Property(t => t.Departamento).HasColumnName("Departamento");
            this.Property(t => t.Piso).HasColumnName("Piso");
            this.Property(t => t.Barrio).HasColumnName("Barrio");

            // Relationships
            this.HasRequired(t => t.Cliente)
                .WithMany(t => t.DomicilioList)
                .HasForeignKey(d => d.ClienteId);         
        }
    }
}
